package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysPower;
import com.ruoyi.system.service.ISysPowerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供货能力Controller
 *
 * @author ruoyi
 * @date 2024-07-27
 */
@RestController
@RequestMapping("/system/power")
public class SysPowerController extends BaseController
{
    @Autowired
    private ISysPowerService sysPowerService;

    /**
     * 查询供货能力列表
     */
    @PreAuthorize("@ss.hasPermi('system:power:list')")
    @GetMapping("/list")
    public AjaxResult list(SysPower sysPower)
    {
        List<SysPower> list = sysPowerService.selectSysPowerList(sysPower);
        return success(list);
    }

    /**
     * 导出供货能力列表
     */
    @PreAuthorize("@ss.hasPermi('system:power:export')")
    @Log(title = "供货能力", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPower sysPower)
    {
        List<SysPower> list = sysPowerService.selectSysPowerList(sysPower);
        ExcelUtil<SysPower> util = new ExcelUtil<SysPower>(SysPower.class);
        util.exportExcel(response, list, "供货能力数据");
    }

    /**
     * 获取供货能力详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:power:query')")
    @GetMapping(value = "/{powerId}")
    public AjaxResult getInfo(@PathVariable("powerId") Long powerId)
    {
        return success(sysPowerService.selectSysPowerByPowerId(powerId));
    }

    /**
     * 新增供货能力
     */
    @PreAuthorize("@ss.hasPermi('system:power:add')")
    @Log(title = "供货能力", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPower sysPower)
    {
        return toAjax(sysPowerService.insertSysPower(sysPower));
    }

    /**
     * 修改供货能力
     */
    @PreAuthorize("@ss.hasPermi('system:power:edit')")
    @Log(title = "供货能力", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPower sysPower)
    {
        return toAjax(sysPowerService.updateSysPower(sysPower));
    }

    /**
     * 删除供货能力
     */
    @PreAuthorize("@ss.hasPermi('system:power:remove')")
    @Log(title = "供货能力", businessType = BusinessType.DELETE)
	@DeleteMapping("/{powerIds}")
    public AjaxResult remove(@PathVariable Long[] powerIds)
    {
        return toAjax(sysPowerService.deleteSysPowerByPowerIds(powerIds));
    }
}
